/*
 * 对字符串加密
 * 字符串最多支持125个字符,不支持汉字
 */
var faultNum = 0;//错误次数初始化
function qdEncryptValue(info){
    if(faultNum>=3){//3次以上
        return -1;
    }
    if(info == ''){
        return '';
    }
    var rsa_n = "BEF9BDC48C844B688321E89AFCBF999B3327DB6997F2736AEFDACCFA1C1EA8C62CD3C80E0F7910B1A25546885388581499610B37AA1491F09B33C38DAA4962238EC356A216A458AC736033402A1500C99702978A1550627A25FE0EB4CEA89BA533FD2DCAD81B2F6681D6D26BB96C4F1D7174BB1D00EB6610680EC535B9774621";  
    setMaxDigits(131); //131 => n的十六进制位数/2+3  
    var key = new RSAKeyPair("10001", '', rsa_n); //10001 => e的十六进制      
    var encryptinfo = encryptedString(key, info);
    //针对像华为浏览器加密偶尔出错问题
    if(encryptinfo.length<40){
        faultNum++;
        return qdEncryptValue(info);
    }
    faultNum = 0;//重置错误次数
    return encryptinfo;
}

/*
 * 对参数串整体加密
 */
function qdEncryptParams(paramStr,token){
    if(paramStr == ''){
        return '';
    }
    var k = token.substring(0,16);
    var v = token.substring(26);
    var key = CryptoJS.enc.Latin1.parse(k);
    var iv = CryptoJS.enc.Latin1.parse(v);
    //console.log('token=' + token + ';;; key=' + k + ';;; iv=' + v);
    var encryptinfo = CryptoJS.AES.encrypt(paramStr, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding }).toString();
    return encryptinfo;   
}

/*
 * 去掉字符串首尾以及中间的空格
 */ 
function trimStr(str){
    str = str.replace(/\s/g, "");
    return str.replace(/(^\s*)|(\s*$)/g,"");
}

/**
 * 判断参数是否加密失败
 */
function checkData(arr){
    if($.inArray(-1, arr)==-1){
        return true;
    }
    return false;
}
